package com.e2oto.seller.modules.seller.presenter;

import com.alibaba.fastjson.JSONObject;
import com.e2oto.seller.common.EasyAES;
import com.e2oto.seller.common.base.BasePresenter;
import com.e2oto.seller.common.http.ProgressSubscriber;
import com.e2oto.seller.common.http.ProgressSubscriberOnNextListener;
import com.e2oto.seller.common.utils.RetrofitUtils;
import com.e2oto.seller.modules.SellerApp;
import com.e2oto.seller.modules.seller.bean.GoodsInfoBean;
import com.e2oto.seller.modules.seller.views.GoodsPreviewView;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by ZhangLiQiang on 2017/11/13.
 */

public class GoodsPreviewPresenter extends BasePresenter<GoodsPreviewView> {

    public void getGoodsInfo(String goodsId) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("goods_id", goodsId);
        jsonObject.put("seller_id", SellerApp.sellerId);
        String param = EasyAES.encrypt(jsonObject);

        RetrofitUtils.getApiService().getGoodsInfo(param, SellerApp.versionName)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ProgressSubscriber(new ProgressSubscriberOnNextListener<GoodsInfoBean>() {
                    @Override
                    public void onNext(GoodsInfoBean bean) {
                        getView().getGoodsInfoCallback(bean);
                    }
                }, getContext()));

    }
}
